package com.Service;
import com.Dao.*;
import com.Dao.Imp.GetUserDaoImp;
import com.Dao.Imp.UpdateUserDaoImp;
import com.pojo.Author;
import com.pojo.Book;
import com.pojo.BookProfile;
import com.pojo.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

@Service
@Slf4j
public class ManagerService {
    @Autowired
    private GetUserDaoImp getUserDaoImp;
    @Autowired
    private UpdateUserDao updateUserDaoImp;
    @Autowired
    private GetAuthorDao getAuthorDaoImp;
    @Autowired
    private UpdateAuthorDao updateAuthorDaoImp;
    @Autowired
    private  DeleteInfoDao deleteInfoDaoImp;
    @Autowired
    private GetBookDao getBook;
    public Map<String,Object> getUser(int page, int rows) throws SQLException {
        return getUserDaoImp.getAllUser(page,rows);
    }
    public void updateUserInfo(User user) throws SQLException {
         updateUserDaoImp.update(user.getId(),user.getUsername(),user.getPassword());
    }
    public Map<String,Object> getAuthor(int page, int rows) throws SQLException {
        return getAuthorDaoImp.getAllAuthor(page,rows);
    }
    public void updateAuthorInfo(Author author) throws SQLException {
        updateAuthorDaoImp.updateAuthor(author);
    }
    public void updateStatus(String id,String status) throws SQLException {
        int sta=Integer.parseInt(status);
        int userid=Integer.parseInt(id);
        updateUserDaoImp.updateStatus(userid,sta);
    }
    public void deleteAuthorInfo(String id) throws SQLException {
        int authorId=Integer.parseInt(id);
        deleteInfoDaoImp.deleteAuthorInfo(authorId);
    }
    public void deleteUserInfo(String id) throws SQLException {
        int userId=Integer.parseInt(id);
        deleteInfoDaoImp.deleteUserInfo(userId);
    }
    public Map<String,Object> getALlBook(int page,int rows) throws SQLException {
       return getBook.getBookInfo(page,rows);
    }
    public void deleteBookInfo(String id) throws SQLException {
        int bookId=Integer.parseInt(id);
        deleteInfoDaoImp.deleteBookInfo(bookId);
    }
    public List<BookProfile> getBookProfile(String id) throws SQLException {
        int bookId=Integer.parseInt(id);
        return getBook.getBookProfile(bookId);
    }
}
